package com.vanke.devops.domain.manager.docker.extend.command.impl;

import com.github.dockerjava.core.command.AbstrDockerCmd;
import com.github.dockerjava.core.util.FiltersBuilder;
import com.vanke.core.util.StringUtil;
import com.vanke.devops.domain.manager.docker.extend.command.ListServicesCmd;
import com.vanke.devops.domain.manager.docker.extend.enums.ServiceModel;
import com.vanke.devops.domain.manager.docker.extend.model.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 陈景阳
 * @since 2018/6/7
 */
public class ListServicesCmdImpl extends AbstrDockerCmd<ListServicesCmd, List<Service>> implements ListServicesCmd {

    private FiltersBuilder filters = new FiltersBuilder();

    public ListServicesCmdImpl(ListServicesCmd.Exec exec) {
        super(exec);
    }

    @Override
    public Map<String, List<String>> getFilters() {
        return filters.build();
    }

    @Override
    public ListServicesCmd withId(String id) {
        if(StringUtil.isNotEmpty(id)){
            filters.withFilter("id",id);
        }
        return this;
    }

    @Override
    public ListServicesCmd withLabel(String label) {
        if(StringUtil.isNotEmpty(label)){
            filters.withFilter("label",label);
        }
        return this;
    }

    @Override
    public ListServicesCmd withModel(ServiceModel model) {
        filters.withFilter("model",model.getValue());
        return this;
    }

    @Override
    public ListServicesCmd withName(String name) {
        if(StringUtil.isNotEmpty(name)){
            filters.withFilter("name",name);
        }
        return this;
    }
}
